<?PHP
if (!session_start()) { session_start(); };
/*if (!isset($_SESSION['lgnapproved'])) {
	die(header('Location: login.php'));
}*/
include("functions.php");
include("cnnxn.php");
connect();

$SQLview='SELECT * FROM Events WHERE TournamentID='.$_GET['tid'].' ORDER BY StartDate,GenderID,DivisionID DESC;';
$sendit_view=mysqli_query($db,$SQLview) or die(mysqli_error($db));

$SQLgt='SELECT * FROM Tournaments WHERE TournamentID='.$_GET['tid'].';';
$sendgt=mysqli_query($db,$SQLgt) or die(mysqli_error($db));
$RSgt=mysqli_fetch_object($sendgt);

$thisYear=date("Y");
$years=1989;
$followingYears=$thisYear+3;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>daleclark.net</title>
<link type="text/css" rel="stylesheet" href="adminstyles.css" />
</head>
<body>
<div id="adminwrapper">
<div id="adminlogo"></div>
<?PHP navigation(); ?>
<div id="admincontent">
<h3>Events for Tournament : <?PHP print $RSgt->StartDate; ?></h3>

<p><a href="Tournaments_viewall.php" style="font-size:10px; text-transform:uppercase;"><img src="../images/icon_back.png" style="border:none;" /> back to Tournaments</a></p>

<div style="float:left; width:500px; padding-right:25px; margin-right:25px; border-right:1px solid #FFFFFF;">
<table style="width:500px; border-collapse:collapse;">
<tr><td>&nbsp;</td><td style="width:100px;"><strong>Start Date</strong></td><td style="width:100px;"><strong>Gender</strong></td><td><strong>Division</strong></td><td>&nbsp;</td></tr>
<?PHP 
$backgroundcolor="#2883D4";
while ($RSview=mysqli_fetch_object($sendit_view)) {
	
	if ($backgroundcolor=="#2883D4") {
		$backgroundcolor="#2F93E9";
	} else {
		$backgroundcolor="#2883D4";
	}
	$SQLgg='SELECT * FROM Gender WHERE GenderID='.$RSview->GenderID.';';
	$sendgg=mysqli_query($db,$SQLgg) or die(mysqli_error($db));
	$RSgg=mysqli_fetch_object($sendgg);
	
	$SQLgd='SELECT * FROM Divisions WHERE DivisionID='.$RSview->DivisionID.';';
	$sendgd=mysqli_query($db,$SQLgd) or die(mysqli_error($db));
	$RSgd=mysqli_fetch_object($sendgd);
	
	if (isset($_GET['er']) && $_GET['er']==$RSview->EventID) {
		print '<tr><td colspan="5"><p style="margin-bottom:0px; color:#990000;">There are still Results listed for this event. Please remove those first.</p></td></tr>';
	}

	print '<tr style="background:'.$backgroundcolor.'; width:500px;"><td style="text-align:center;"><a href="Events_del.php?tid='.$_GET['tid'].'&eid='.$RSview->EventID.'" class="deletelink" title="DELETE" onclick="return confirm(\'Are sure you want to PERMANENTLY DELETE this Event?\')"><img src="../images/icon_delete.png" height="12px" border="0" /></a></td><td><a href="Events_mod.php?tid='.$_GET['tid'].'&id='.$RSview->EventID.'">'.$RSview->StartDate.'</td><td>'.$RSgg->Gender.'</td><td>'.$RSgd->Division.'</a></td><td><a href="Results_viewall.php?tid='.$_GET['tid'].'&eid='.$RSview->EventID.'&gen='.$RSgg->Gender.'&div='.$RSgd->Division.'">RESULTS</a></td></tr>';
}
?>
</table>

<div class="clear"></div>
<p>&nbsp;</p>
</div>
<div style="float:left; width:500px;">
<h3>Add Event</h3>
<form name="addForm" method="POST" action="Events_add.php?tid=<?PHP print $_GET['tid']; ?>">
<input name="TournamentID" type="hidden" value="<?PHP print $_GET['tid'] ?>" />
<?PHP list($year,$month,$day) = split("-",$RSgt->StartDate); ?>
<p><span class="label">Start Date</span><span class="inputbox">day: <select name="eventdate_day">
<option value="01"<?PHP if ($day=='01') { print ' selected'; } ?>>01</option>
<option value="02"<?PHP if ($day=='02') { print ' selected'; } ?>>02</option>
<option value="03"<?PHP if ($day=='03') { print ' selected'; } ?>>03</option>
<option value="04"<?PHP if ($day=='04') { print ' selected'; } ?>>04</option>
<option value="05"<?PHP if ($day=='05') { print ' selected'; } ?>>05</option>
<option value="06"<?PHP if ($day=='06') { print ' selected'; } ?>>06</option>
<option value="07"<?PHP if ($day=='07') { print ' selected'; } ?>>07</option>
<option value="08"<?PHP if ($day=='08') { print ' selected'; } ?>>08</option>
<option value="09"<?PHP if ($day=='09') { print ' selected'; } ?>>09</option>
<option value="10"<?PHP if ($day=='10') { print ' selected'; } ?>>10</option>
<option value="11"<?PHP if ($day=='11') { print ' selected'; } ?>>11</option>
<option value="12"<?PHP if ($day=='12') { print ' selected'; } ?>>12</option>
<option value="13"<?PHP if ($day=='13') { print ' selected'; } ?>>13</option>
<option value="14"<?PHP if ($day=='14') { print ' selected'; } ?>>14</option>
<option value="15"<?PHP if ($day=='15') { print ' selected'; } ?>>15</option>
<option value="16"<?PHP if ($day=='16') { print ' selected'; } ?>>16</option>
<option value="17"<?PHP if ($day=='17') { print ' selected'; } ?>>17</option>
<option value="18"<?PHP if ($day=='18') { print ' selected'; } ?>>18</option>
<option value="19"<?PHP if ($day=='19') { print ' selected'; } ?>>19</option>
<option value="20"<?PHP if ($day=='20') { print ' selected'; } ?>>20</option>
<option value="21"<?PHP if ($day=='21') { print ' selected'; } ?>>21</option>
<option value="22"<?PHP if ($day=='22') { print ' selected'; } ?>>22</option>
<option value="23"<?PHP if ($day=='23') { print ' selected'; } ?>>23</option>
<option value="24"<?PHP if ($day=='24') { print ' selected'; } ?>>24</option>
<option value="25"<?PHP if ($day=='25') { print ' selected'; } ?>>25</option>
<option value="26"<?PHP if ($day=='26') { print ' selected'; } ?>>26</option>
<option value="27"<?PHP if ($day=='27') { print ' selected'; } ?>>27</option>
<option value="28"<?PHP if ($day=='28') { print ' selected'; } ?>>28</option>
<option value="29"<?PHP if ($day=='29') { print ' selected'; } ?>>29</option>
<option value="30"<?PHP if ($day=='30') { print ' selected'; } ?>>30</option>
<option value="31"<?PHP if ($day=='31') { print ' selected'; } ?>>31</option>
</select>&nbsp;month: <select name="eventdate_month">
<option value="01"<?PHP if ($month=='01') { print ' selected'; } ?>>01</option>
<option value="02"<?PHP if ($month=='02') { print ' selected'; } ?>>02</option>
<option value="03"<?PHP if ($month=='03') { print ' selected'; } ?>>03</option>
<option value="04"<?PHP if ($month=='04') { print ' selected'; } ?>>04</option>
<option value="05"<?PHP if ($month=='05') { print ' selected'; } ?>>05</option>
<option value="06"<?PHP if ($month=='06') { print ' selected'; } ?>>06</option>
<option value="07"<?PHP if ($month=='07') { print ' selected'; } ?>>07</option>
<option value="08"<?PHP if ($month=='08') { print ' selected'; } ?>>08</option>
<option value="09"<?PHP if ($month=='09') { print ' selected'; } ?>>09</option>
<option value="10"<?PHP if ($month=='10') { print ' selected'; } ?>>10</option>
<option value="11"<?PHP if ($month=='11') { print ' selected'; } ?>>11</option>
<option value="12"<?PHP if ($month=='12') { print ' selected'; } ?>>12</option>
</select>&nbsp;year: <select name="eventdate_year">
<?PHP
while ($years<=$followingYears) {
	$years++;
	print '<option value="'.$years.'"';
	if ($years==$year) {
		print ' selected';
	}
	print '> '.$years.' </option>';
}
?>
</select></span></p>
<p><span class="label">Gender</span><span class="inputbox"><select name="GenderID">
<?PHP 
$SQLgg='SELECT * FROM Gender;';
$sendgg=mysqli_query($db,$SQLgg) or die(mysqli_error($db));
while ($RSgg=mysqli_fetch_object($sendgg)) {
	print '<option value="'.$RSgg->GenderID.'">'.$RSgg->Gender.'</option>';
}
?>
</select></span></p>
<p><span class="label">Division</span><span class="inputbox"><select name="DivisionID"></span></p>
<?PHP 
$SQLgd='SELECT * FROM Divisions;';
$sendgd=mysqli_query($db,$SQLgd) or die(mysqli_error($db));
while ($RSgd=mysqli_fetch_object($sendgd)) {
	print '<option value="'.$RSgd->DivisionID.'">'.$RSgd->Division.'</option>';
}
?>
</select></span></p>
<p><span class="label">Team Size</span><span class="inputbox"><select name="TeamSize">
<option value="1">1</option>
<option value="2">2</option>
<option value="4">4</option>
</select></span></p>
<p><span class="label">Number Of Teams</span><span class="inputbox"><input name="NumberOfTeams" type="text" /></span></p>
<input type="submit" value="submit" name="submit" /></form>

</div>

</div>
</div>
</body>
</html>
<?PHP
mysqli_close($db);
?>